#include "registrationpage.h"
#include <QVBoxLayout>
#include <QLabel>
#include <QSpacerItem>
#include <QMessageBox>

RegistrationPage::RegistrationPage(QWidget *parent) : QWidget(parent) {
    // 创建主布局
    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->setContentsMargins(20, 20, 20, 20); // 设置边距
    layout->setSpacing(15); // 设置间距

    // 添加标题
    QLabel *titleLabel = new QLabel("我的挂号", this);
    titleLabel->setStyleSheet("font-size: 32px; font-weight: bold; color: #2980B9; text-align: center;"); // 设置标题样式
    layout->addWidget(titleLabel);

    // 创建正在挂号列表
    appointmentsList = new QListWidget(this);
    appointmentsList->setStyleSheet("font-size: 18px; padding: 10px; background-color: #ECF0F1; border: 1px solid #BDC3C7; border-radius: 5px;");
    layout->addWidget(appointmentsList);

    // 添加示例数据
    appointmentsList->addItem("科室: 心内科 - 医生: 张医生");
    appointmentsList->addItem("科室: 外科 - 医生: 李医生");

    // 创建取消挂号按钮
    cancelButton = new QPushButton("取消挂号", this);
    cancelButton->setStyleSheet("background-color: #E74C3C; color: white; font-size: 20px; padding: 12px; border: none; border-radius: 5px;");
    connect(cancelButton, &QPushButton::clicked, this, &RegistrationPage::cancelAppointment);
    layout->addWidget(cancelButton);

    // 创建底部空间
    layout->addSpacerItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));

    // 设置布局
    setLayout(layout);
}

// 取消挂号的槽函数
void RegistrationPage::cancelAppointment() {
    QListWidgetItem *selectedItem = appointmentsList->currentItem(); // 获取当前选中的项目
    if (selectedItem) {
        // 弹出确认对话框
        QMessageBox::StandardButton reply;
        reply = QMessageBox::question(this, "取消挂号", "确定要取消此挂号吗？", QMessageBox::Yes | QMessageBox::No);

        if (reply == QMessageBox::Yes) {
            delete selectedItem; // 删除选中的挂号
        }
    } else {
        QMessageBox::warning(this, "警告", "请先选择一个挂号进行取消。");
    }
}
